package com.example.project.controller;

import com.example.project.entity.Attendance;
import com.example.project.service.IAttendanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "打卡信息表")
@RestController
public class AttendanceController {
    @Autowired
    private IAttendanceService attendanceService;
    @CrossOrigin

    @ApiOperation(value = "对打卡信息的添加")
    @GetMapping("getaddAttendance")
    public int insert(Attendance attendance){
        System.out.println("进入增加方法");
        return attendanceService.add(attendance);
    }

    @ApiOperation(value = "查询所有打卡信息方法")
    @GetMapping("/getallattendance")
    public List<Attendance> getAllAttendance(Attendance attendance){
        System.out.println("进入查询所有打卡信息的方法");
        List<Attendance> attendanceList=attendanceService.getAllAttendance(attendance);
        return attendanceList;
    }

    @ApiOperation(value = "删除单条打卡信息")
    @GetMapping("/deleteAttendance")
    public int deleteAttendance(int id){
        System.out.println("进入打卡信息删除方法");
        int returnValus=0;
        if(id!=0){
            Attendance attendance=new Attendance();
            attendance.setAttendanceId(id);
            returnValus= attendanceService.deleteAttendance(attendance);
        }
        return returnValus;
    }

    @ApiOperation(value = "对打卡信息更新方法")
    @GetMapping("/updateAttendance")
    public int updateAttendance(Attendance attendance){
        System.out.println("进入打卡信息更新方法");
        return attendanceService.updateAttendance(attendance);
    }

    @ApiOperation(value = "获取单条打卡数据")
    @GetMapping("/getoneAttendance")
    public Attendance getAttendance(int id){
        Attendance attendance=new Attendance();
        System.out.println("");
        if(id!=0){
            Attendance attendance1=new Attendance();
            attendance1.setAttendanceId(id);
            attendance=attendanceService.getAttendance(attendance1);
            System.out.println(""+attendance.getAttendanceId());
        }
        return attendance;
    }
}

